﻿namespace Modbus.Messages
{
	internal sealed class ReadWriteMultipleRegistersRequest : ModbusMessage
	{
		private ushort readStartingAddress;
		private ushort readQuantity;
		private ushort writeStartingAddress;
		private ushort writeQuantity;
		private byte[] writeRegisters;

		public override void Read(ModbusReader reader)
		{
			base.Read(reader);

			this.readStartingAddress = reader.ReadUInt16();
			this.readQuantity = reader.ReadUInt16();
			this.writeStartingAddress = reader.ReadUInt16();
			this.writeQuantity = reader.ReadUInt16();
			this.writeRegisters = DataUtility.ReadData(reader);
		}

		public override void Write(ModbusWriter writer)
		{
			base.Write(writer);

			writer.Write(this.readStartingAddress);
			writer.Write(this.readQuantity);
			writer.Write(this.writeStartingAddress);
			writer.Write(this.writeQuantity);
			DataUtility.WriteData(writer, this.writeRegisters);
		}

		public ushort ReadStartingAddress
		{
			get { return this.readStartingAddress; }
			set { this.readStartingAddress = value; }
		}

		public ushort ReadQuantity
		{
			get { return this.readQuantity; }
			set { this.readQuantity = value; }
		}

		public ushort WriteStartingAddress
		{
			get { return this.writeStartingAddress; }
			set { this.writeStartingAddress = value; }
		}

		public ushort WriteQuantity
		{
			get { return this.writeQuantity; }
			set { this.writeQuantity = value; }
		}

		public byte[] WriteRegisters
		{
			get { return this.writeRegisters; }
			set { this.writeRegisters = value; }
		}
	}
}
